package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
	"gorm.io/plugin/soft_delete"
)

type GoodsReview struct {
	ID        string                `json:"id" gorm:"primaryKey;column:id;type:bigint"`
	OpenID    string                `json:"openid" gorm:"column:openid;type:varchar(50);index:idx_openid;comment:openid"`
	OrderID   string                `json:"order_id" gorm:"column:order_id;type:int;size:64;index:idx_orderid;not null;comment:订单id"`
	GoodsID   string                `json:"goods_id" gorm:"column:goods_id;type:int;size:64;index:idx_goodsid;comment:商品id"`
	Star      string                `json:"star" gorm:"column:star;type:decimal(2,1);default:0.0;comment:星级评价"`
	Content   string                `json:"content" gorm:"column:content;type:string;size:120;comment:评价内容"`
	Images    string                `json:"images" gorm:"column:images;type:text;comment:图片"`
	Visible   int                   `json:"visible" gorm:"column:visible;type:int;size:8;default:2;comment:是否可见"`
	AuditID   string                `json:"audit_id" gorm:"column:audit_id;type:int;size:64;default:null; comment:审核记录id"`
	CreatedAt int64                 `json:"created_at" gorm:"column:created_at;autoCreateTime;type:int;size:64;index:idx_createdAt;comment:创建时间"`
	UpdatedAt int64                 `json:"updated_at" gorm:"column:updated_at;type:int;size:64"`
	DeletedAt soft_delete.DeletedAt `json:"deleted_at" gorm:"column:deleted_at;type:bigint;default:0;comment:删除时间"`
}

func (GoodsReview) TableName() string {
	return "goods_review"
}

// BeforeCreate 自增id
func (m *GoodsReview) BeforeCreate(tx *gorm.DB) (err error) {
	if m.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	m.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &GoodsReview{})
}
